package com.kun.service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kun.domain.TFollowingGroup;
import com.kun.service.mapper.TFollowingGroupMapper;
import com.kun.service.service.ITFollowingGroupService;
import com.kun.service.util.UserContext;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TFollowingGroupServiceImpl extends ServiceImpl<TFollowingGroupMapper, TFollowingGroup>
        implements ITFollowingGroupService {

    @Override
    public boolean insert(TFollowingGroup tFollowingGroup) {
        return save(tFollowingGroup);
    }

    /**
     * 根据群组类型查找当前用户的群组
     */
    @Override
    public TFollowingGroup getGroupByTypeId(String id) {
        Long userId = UserContext.getUserId();
        return lambdaQuery().eq(TFollowingGroup::getUserId, userId).
                eq(TFollowingGroup::getType, id).last("LIMIT 1").one();
    }

    /**
     * 根据群组ID查询
     */
    @Override
    public TFollowingGroup getFollowGroupById(Long groupId) {
        return getById(groupId);
    }

    /**
     * 根据用户ID查询所有的群组
     */
    @Override
    public List<TFollowingGroup> getUserFollowingGroups(String userId) {
        return lambdaQuery().eq(TFollowingGroup::getUserId, userId).list();
    }
}
